package top.z.orm.handle.osql.core;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

class OneTimeParameter {

    private static final ThreadLocal<Map<String, Object>> local = new ThreadLocal<>();
    private static final String                           tRue  = "tRue";

    private OneTimeParameter() {
    }

    public static Object getAttribute(String key) {
        Map<String, Object> map = local.get();
        if (null == map) {
            return null;
        }
        Object obj = map.get(key);
        //取后即删
        map.remove(key);
        return obj;
    }

    public static void setAttribute(String key, Object obj) {
        if (obj == null) {
            return;
        }
        Map<String, Object> map = local.get();
        if (null == map) {
            map = new ConcurrentHashMap<>();
        }
        map.put(key, obj);
        local.set(map);
    }

    public static void setAttribute(String key) {
        setAttribute(key, tRue);
    }
}